<?php
namespace app\manage\controller;
use app\manage\model\User as Users;
use think\Session;

class Myself extends Comm{
    public function editmyself(){
        if(isset($_POST['submit'])){
            $id = input('hid');
            $name = input('name');
            $user = new Users();

            $moddo = $user->editmyself($id,$name);

            if($moddo!==false){
                $this->success('修改成功,重新登陆后生效');
            }else{
                $this->error('修改失败');
            }
        }else{
            return view('editmyself');
        }
    }
    public function editroot()
    {
        if(request()->isPost())
        {
            $user = new Users();
            $id = session::get('userid');
            $querys = $user->where('id', $id)->find();
            $oldrootsjk = $querys['root'];
            $randomcode = $querys['randomcode'];
            $newroot = md5(input('newroot').$randomcode);
            $oldrootsr = md5(input('oldroot').$randomcode);
            if($oldrootsjk !== $oldrootsr)
            {
                return $this->error('原密码输入错误');
            }else
            {
                    if(input('newroot') !==input('enroot'))
                    {
                        return $this->error('新密码与确认密码不一致');
                    }
                    else
                    {
                        $queryu = $user->editroot($id,$newroot);
                        if($queryu !== false)
                        {
                            return $this->success('修改成功,请重新登录','manage/Quit/Quit');
                        }else
                        {
                            return $this->error('修改失败');
                        }
                    }

            }
        }
        return view('editroot');
    }
}